<template>
  <div class="music-list">
    <div class="bg-box" :style="bgStyle">
      <div class="header" :style="bgStyle">
        <div class="header-filter">
          <img src="@/assets/img/icon-back.png" alt="返回" title="返回" @click="toBack">
          <h1 v-html="title"></h1>
        </div>
      </div>
      <div class="filter" ref="filter"></div>
    </div>
    <Scroll :data="songs" class="scroll" ref="scroll">
      <SongList @select="selectItem" @scrollRefresh="scrollRefresh" :songs="songs" :rank="rank"></SongList>
    </Scroll>
  </div>
</template>

<script>
import SongList from "base/songList/songList"
import Scroll from 'base/scroll/Scroll'
import { mapActions } from 'vuex'

export default {
  components: {
    SongList,
    Scroll
  },
  props: {
    bgImage: {
      type: String,
      default: ''
    },
    songs: {
      type: Array
    },
    title: {
      type: String,
      default: ''
    },
    rank: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      vkey: '',
      item: '',
      index: ''
    };
  },
  methods: {
    toBack: function() {
      this.$router.go(-1)
    },
    scrollRefresh() {
      this.$refs.scroll.refresh()
    },
    selectItem(item, index) {
      this.index = index
      this.item = item
      this.addMapActions(this.item, this.index)
    },
    addMapActions(item, index) {
      var that = this
      this.selectPlay({
        list: that.songs,
        index: index
      })
    },
    ...mapActions(["selectPlay"])
  },
  computed: {
    bgStyle() {
      return `background-image:url(${this.bgImage})`
    }
  }
}
</script>

<style scoped lang="scss">
@import "@/assets/css/mixin.scss";
.bg-box {
  width: 100%;
  height: 39vh;
  background-size: 100% auto;
  position: relative;
}
.bg-box .header {
  width: 100%;
  height: rem(45);
  background-size: 100% auto;
  color: #fff;
  position: relative;
  z-index: 300;
}
.header .header-filter {
  width: 100%;
  height: 100%;
  background: rgba(7, 17, 27, 0.4);
}
.header-filter img {
  width: rem(32);
  height: rem(32);
  position: absolute;
  top: rem(6);
  left: rem(12);
}
.header-filter h1 {
  width: 100%;
  text-align: center;
  line-height: rem(45);
  font-size: rem(18);
}
.bg-box .filter {
  width: 100%;
  height: 100%;
  background: rgba(7, 17, 27, 0.4);
  position: absolute;
  top: 0;
  left: 0;
}
.scroll {
  width: 100%;
  height: 61vh;
}
</style>
